import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelUtil } from "../../../scene/player/info/ModelUtil";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { MountResInfo } from "../../../scene/player/info/MountResInfo";
import { Language } from "../../../../../extend/language/Language";
import { MountType } from "../../../scene/player/entity/MountType";
import { ActionType } from "../../../scene/modle/data/ActionType";
import { DirectionType } from "../../../scene/modle/data/DirectionType";
//class MountChangeCellRenderer
    
    export  class MountChangeCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._dtArr = [];
            this.init();
            this.scrollRect = new Object /* flash.geom.Rectangle */(0, 0, 196, 186);
            return;
        }

        /* internal  */init(): void
        {
            this._windowBbg = ObjCreate.createBg(0, 0, 196, 186, this);
            ObjCreate.createLoadedBitmap("mountChangeModelBg.jpg", 4, 4, this);
            this._tfName = ObjCreate.createTextField("", 64, 163, 70, 20, this, GlobalStyle.textFormat2);
            this._tfName.autoSize = flash.text.TextFieldAutoSize.CENTER;
            var loc1;
            this.mouseChildren = loc1 = true;
            this.mouseEnabled = loc1;
            this._selectLine = new Object /* flash.display.Sprite */();
            this._selectLine.mouseEnabled = false;
            this._selectLine.graphics.lineStyle(4, 65407, 1);
            this._selectLine.graphics.drawRoundRect(0, 0, width, (height - 1), 6, 6);
            this._selectLine.graphics.endFill();
            this._dtTx = ObjCreate.createTextField("", 30, 137, 150, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._mountModel) 
            {
                this._mountModel.dispose();
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (this._isLock) 
            {
                if (this._selectLine.parent) 
                {
                    removeChild(this._selectLine);
                }
            }
            else if (arg1) 
            {
                if (this._modelID != "") 
                {
                    addChild(this._selectLine);
                }
            }
            else if (this._selectLine.parent) 
            {
                removeChild(this._selectLine);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (arg1) 
            {
                this._modelID = arg1.modelId;
                this._txName = arg1.name;
                this._isLock = arg1.isLock;
                this._dt = arg1.dt;
                if (this._dt === "") 
                {
                    this._dtArr = [];
                }
                else 
                {
                    this._dtArr = this._dt.split(",");
                }
                if (this._mountModel != null) 
                {
                    this._mountModel.dispose();
                }
                else 
                {
                    this._mountModel = new SWFPlayer();
                }
                this._mountModel.loadComplete = this.onLoadCompleteHandler;
                this._mountModel.load(ModelUtil.getModelSWF(this._modelID), ModelType.Mount, new MountResInfo(this._modelID));
                if (this._mountModel.parent == null) 
                {
                    this.addChild(this._mountModel);
                }
                this._tfName.text = this._txName;
                if (this._isLock) 
                {
                    if (this._bmLock != null) 
                    {
                        if (this._bmLock.parent != null) 
                        {
                            this.addChild(this._bmLock);
                        }
                        else 
                        {
                            this.addChild(this._bmLock);
                        }
                    }
                    else 
                    {
                        this._bmLock = ObjCreate.createLoadedBitmap("mountLock.png", 160, 14, this);
                    }
                    var loc1;
                    this.mouseChildren = loc1 = false;
                    this.mouseEnabled = loc1;
                    this.useHandCursor = loc1 = false;
                    this.buttonMode = loc1;
                    this._dtTx.text = "";
                }
                else 
                {
                    if (this._bmLock && this._bmLock.parent == this) 
                    {
                        this.removeChild(this._bmLock);
                    }
                    this.useHandCursor = loc1 = true;
                    this.buttonMode = loc1;
                    this.mouseChildren = loc1 = true;
                    this.mouseEnabled = loc1;
                    if (this._dtArr.length > 0) 
                    {
                        this._dtTx.text = Language.getStringByParam(70158, this._dtArr[0], this._dtArr[1], this._dtArr[2]);
                        this.addChildAt(this._dtTx, this.numChildren);
                    }
                    else 
                    {
                        this._dtTx.text = "";
                    }
                }
            }
            else 
            {
                this.mouseChildren = loc1 = false;
                this.mouseEnabled = loc1;
                if (this._mountModel) 
                {
                    this._mountModel.dispose();
                }
                this._tfName.text = "";
            }
            return;
        }

        /* internal  */onLoadCompleteHandler(arg1: SWFPlayer): void
        {
            this._mountModel.loadComplete = null;
            if (this._mountModel.movieClipData) 
            {
                if (this._mountModel.movieClipData.modleType != MountType.Namorl) 
                {
                    if (this._mountModel.movieClipData.modleType != MountType.Fly) 
                    {
                        if (this._mountModel.movieClipData.modleType == MountType.Rest) 
                        {
                            if (this._mountModel.url != "37041100.swf") 
                            {
                                this._mountModel.sceneX = 90;
                                this._mountModel.sceneY = 115 - this._mountModel.movieClipData.pointY / 2;
                            }
                            else 
                            {
                                this._mountModel.sceneX = 123;
                                this._mountModel.sceneY = 50;
                            }
                            this._mountModel.updateFrame(ActionType.RestMountStand, DirectionType.SouthWest, true);
                        }
                    }
                    else 
                    {
                        if (this._mountModel.url != "37038500.swf") 
                        {
                            this._mountModel.sceneX = 110;
                            this._mountModel.sceneY = 130 - this._mountModel.movieClipData.pointY / 2;
                        }
                        else 
                        {
                            this._mountModel.sceneX = 120;
                            this._mountModel.sceneY = 80;
                        }
                        this._mountModel.updateFrame(ActionType.flyMountStand, DirectionType.SouthWest, true);
                    }
                }
                else 
                {
                    if (this._mountModel.url == "37015100.swf" || this._mountModel.url == "37016100.swf" || this._mountModel.url == "47015100.swf" || this._mountModel.url == "47016100.swf" || this._mountModel.url == "37035100.swf") 
                    {
                        this._mountModel.sceneX = 135;
                        this._mountModel.sceneY = 165;
                    }
                    else if (this._mountModel.url != "37020100.swf") 
                    {
                        this._mountModel.sceneX = 115;
                        this._mountModel.sceneY = 115;
                    }
                    else 
                    {
                        this._mountModel.sceneX = 145;
                        this._mountModel.sceneY = 115;
                    }
                    this._mountModel.updateFrame(ActionType.MountStand, DirectionType.SouthWest, true);
                }
            }
            this._mountModel.updateCurrentFrame(0);
            this._mountModel.play();
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this._mountModel.dispose();
            this._dtTx.text = "";
            if (this._windowBbg && this._windowBbg.parent == this) 
            {
                this.removeChild(this._windowBbg);
            }
            if (this._bmLock && this._bmLock.parent == this) 
            {
                this.removeChild(this._bmLock);
            }
            super.dispose(arg1);
            return;
        }

        /* internal */ /* var */_windowBbg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_modelID: string;

        /* internal */ /* var */_txName: string;

        /* internal */ /* var */_isLock: Boolean;

        /* internal */ /* var */_dt: string;

        /* internal */ /* var */_dtArr: Array<any>;

        /* internal */ /* var */_mountModel: SWFPlayer;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmLock: Object /* flash.display.Bitmap */;

        protected /* var */_selectLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_dtTx: Object /* flash.text.TextField */;
    }
